7

I always use NVL() for assigning a default value when the result is null.

However in PostgreSql there is only COALESCE().

Can I give the COALESCE function an alias so it executes with NVL?

Or can I copy the function declaration somehow?

2
  • What's wrong with using coalesce() it's part of the SQL standard and also supported by Oracle. Commented Oct 28, 2016 at 8:27
  • 3
    @a_horse_with_no_name May sound trite but saving a few letters in the case of applying this function to dozens of columns can matter. Commented Oct 10, 2019 at 22:39

1 Answer 1

7

You can use this wrapper:

create or replace function nvl (anyelement, anyelement)
returns anyelement language sql as $$
    select coalesce($1, $2)
$$;

See also Oracle Differences between NVL and Coalesce.

Sign up to request clarification or add additional context in comments.

2 Comments

for me this does not work ATM - dba.stackexchange.com/questions/307269/…
Well, your function does not work, mine is OK.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.